package com.copa.l485;

/**
 * @author copa
 * @createDate 2022-06-02 15:44
 * @function 动态规划法
 */
public class Test2 {

    public int findMaxConsecutiveOnes(int[] nums) {
        int result = 0;
        int[] dp = new int[nums.length + 1];
        dp[0] = nums[0] == 0 ? 0 : 1;
        result = dp[0];
        for (int i = 1; i < nums.length; i++) {
            if (nums[i] == 1) {
                dp[i] = dp[i - 1] + 1;
                continue;
            }
            dp[i] = 0;
            result = Math.max(dp[i - 1], result);
        }
        result = Math.max(dp[nums.length - 1], result);
        return result;
    }

    public static void main(String[] args) {
        int[] nums = {1,1,0,1,1,1};
        System.out.println(new Test2().findMaxConsecutiveOnes(nums));
    }
}
